/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Operations.Bit;

import Operations.*;
import java.awt.image.BufferedImage;

/**
 *
 * @author littlechild
 */
public class OpLinearization implements Operation{

    public BufferedImage operate(BufferedImage image, double[] paras) {
        double lightness=paras[0];
        double contrast=paras[1];
        int rgb;
        int gray;
        BufferedImage returnImage=new BufferedImage(image.getWidth(),image.getHeight(),image.getType());
        for(int i=0;i!=image.getWidth();++i) {
            for (int j=0;j!=image.getHeight();++j) {
                rgb=image.getRGB(i, j);
                gray=CommonFunc.getGray(rgb);
                //allow wrap up
                //gray=((int)(contrast*gray+lightness))&0xff;
                //do not allow wrap up
                gray=(int)(contrast*gray+lightness);
                gray=(gray>0xff) ? 0xff : gray;
                gray=(gray<0) ? 0 : gray;
                returnImage.setRGB(i, j,(gray)|(gray<<8)|(gray<<16));
            }
        }
        return returnImage;
    }

}
